package com.addTools;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        //首先，这是个单例模式的问题，学生得一个一个的出去，最后才出门，但是结果却是
        //这里就是让所有的线程都阻塞在了关门这一步，直到满足要求才结束
        CountDownLatch countDownLatch = new CountDownLatch(10);

        for (int i = 1; i <=10; i++) {
            new Thread(()->{
                System.out.println("学生"+Thread.currentThread().getName()+"出去了");
                countDownLatch.countDown();
            },String.valueOf(i)).start();

        }
        countDownLatch.await();

        System.out.println("关门");
    }
}
